import _ from 'lodash';

export const flattenTree = <T>(tree: T[]): (T & { type: boolean })[] => {
  function recurse(
    nodes: any,
    // path: any,
  ): any {
    return _.map(nodes, (node) => {
      // const newPath = _.union(path, [node.name]);
      node.type = !!node?.children;
      return [
        // _.assign({ pathname: newPath.join(' > '), level: path.length }, _.omit(node, 'children')),
        // _.omit(node, 'children'),
        node,
        recurse(
          node.children,
          // newPath
        ),
      ];
    });
  }
  return _.flattenDeep<(T & { type: boolean })[]>(recurse(tree));
};
